#include "discobase.h"
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>

int main(int argc, char** argv) {
	using namespace std;
	using namespace client_server;
	DiscoBase db;
	if(!strcmp(argv[1], "createN")){
		cout << "Creating newsgroup" << endl;
		db.create_newsgroup(argv[2]);
	}
	if(!strcmp(argv[1], "deleteN")) {	
		cout << "Deleting newsgroup" << endl;
		db.delete_newsgroup(atoi(argv[2]));
	}
	if(!strcmp(argv[1], "createA")) {	
		cout << "Creating article" << endl;
		db.create_article(atoi(argv[2]), argv[3], argv[4], argv[5]);
	}
	if(!strcmp(argv[1], "deleteA")) {	
		cout << "Deleting article" << endl;
		db.delete_article(atoi(argv[2]), atoi(argv[3]));
	}
	if(!strcmp(argv[1], "listA")) {	
		cout << "Listing articles" << endl;
		vector<pair<int, string> > NAMES = db.list_articles(atoi(argv[2]));
		for(size_t i = 0; i < NAMES.size(); ++i) {
			cout << NAMES[i].first << " - " << NAMES[i].second << endl;
		}
	}
	if(!strcmp(argv[1], "getA")) {
		cout << "Getting article" << endl;
		Article a = db.get_article(atoi(argv[2]), atoi(argv[3]));
		cout << a.get_name() << endl;
		cout << a.get_author() << endl;
		cout << a.get_content() << endl;
	}
	if(!strcmp(argv[1], "listN")) {
		vector<std::pair<int, std::string> > list = db.list_newsgroups();
		cout << "Listing newsgroups" << endl;
		for(size_t i = 0; i < list.size(); ++i){
			cout << list[i].first << " - " << list[i].second << endl;
		}
	}
}
